#!/bin/sh
#chkconfig: 2345 10 90
# description: Starts and Stops the Tomcat daemon.
##############################################
#Startup script for Tomcat on Linux


# Source function library.
. /etc/init.d/functions

JAVA_HOME=/usr/java/jdk1.8.0_45
CATALINA_HOME=/usr/local/tomcat
export JAVA_HOME
export CATALINA_HOME

getpid() {
  echo `ps -ef|grep /usr/local/webpdf|grep -v grep|awk '{printf $2}'`
}

PIDFILE=/var/run/tomcat.pid
prog=tomcat
PID=`getpid`

if [ -z $PID ] && [ -e ${PIDFILE} ]; then
  rm ${PIDFILE}
fi

if [ -z $PID ] && [ -e /var/lock/subsys/$prog ]; then
  rm -f /var/lock/subsys/$prog
fi


start() {
        PID=`getpid`
        if [ $PID ]; then
                echo "---Tomcat Server already running."
        else
                 echo "Starting Tomcat"
                $CATALINA_HOME/bin/startup.sh

        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
                action $"Starting $prog: " /bin/true
                touch /var/lock/subsys/$prog
        else
                action $"Starting $prog: " /bin/false
        fi
        return $RETVAL
fi
}
stop() {
        PID=`getpid`
        if [ -z $PID ]; then
                echo "Tomcat Server already stopped"
        else
                $CATALINA_HOME/bin/shutdown.sh
                action $"Stopping $porg: " /bin/true
        fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring Tomcat"
stop
sleep 15
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $?
